package com.example.tsproject.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.tsproject.entity.PageBean;
import com.example.tsproject.entity.Posts;
import com.example.tsproject.entity.PostsWithTeacher;
import com.example.tsproject.entity.Videos;
import com.example.tsproject.mapper.VideosMapper;
import com.example.tsproject.service.PostsService;
import com.example.tsproject.mapper.PostsMapper;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author DELL
* @description 针对表【posts】的数据库操作Service实现
* @createDate 2024-09-24 21:09:03
*/
@Service
public class PostsServiceImpl extends ServiceImpl<PostsMapper, Posts>
    implements PostsService{
    @Autowired
    private PostsMapper postsMapper;
    @Autowired
    SqlSession sqlSession;
    @Override
    public PageBean list(Integer pageNum, Integer pageSize) {
//        System.out.println(pageNum);
//        System.out.println(pageSize);
        // 使用 PageHelper 设置分页
        PageHelper.startPage(pageNum, pageSize);

        // 获取分页数据
        List<Posts> posts = postsMapper.selectList(null);  // 你可以根据需要修改查询条件

        com.github.pagehelper.Page<Posts> p = (Page<Posts>) posts;

//            3.封装pageBean对象
        PageBean pageBean = new PageBean(p.getTotal(),p.getResult());
        // 如果需要调试，可以保留这行
        // System.out.println(pageInfo);

        // 返回封装好的分页对象
        return pageBean;
    }

    @Override
    public List<Posts> onlineSql(String sql2) {
        System.out.println(sql2);

        return postsMapper.getPostById222(sql2);
    }

    @Override
    public List<PostsWithTeacher> getPostsWithTeachers() {
        List<PostsWithTeacher> ans=postsMapper.selectPostsWithTeachers();
        System.out.println("*********");
        System.out.println(ans.get(1));
        return postsMapper.selectPostsWithTeachers();
    }


}




